package com.sam.im.heiqun.uis.activities;

import android.os.Bundle;
import android.widget.ListView;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.UserEntivity;
import com.sam.im.heiqun.entities.WalletDetailsEntity;
import com.sam.im.heiqun.nets.PGService;
import com.sam.im.heiqun.uis.adapters.WalletDetailsAdatper;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.nets.callbacks.AbsAPICallback;
import com.yuyh.library.nets.exceptions.ApiException;
import com.yuyh.library.uis.activitys.BaseSwipeBackActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MyWalletDetailsActivity extends BaseSwipeBackActivity {

    private static final String TAG = MyWalletDetailsActivity.class.getSimpleName();
    @BindView(R.id.wallet_details_list_view)
    ListView mListView;

    private List<WalletDetailsEntity> data;
    private WalletDetailsAdatper adapter;
    private PGService mPGservice;

    @Override
    public int getContentViewId() {
        return R.layout.activity_my_wallet_details;
    }

    @Override
    protected String getTitleText() {
        return getResources().getString(R.string.details);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        mPGservice = PGService.getInstance();
        initData();
    }

    private void initData() {
        data = new ArrayList<>();
        UserEntivity userEntivity = ToolsUtils.getUser();
        mPGservice.getWalletHistory(userEntivity.getId() + "").subscribe(new AbsAPICallback<List<WalletDetailsEntity>>() {
            @Override
            protected void onResultError(ApiException ex) {
                showToast(getResources().getString(R.string.net_visit_exception));
            }

            @Override
            public void onNext(List<WalletDetailsEntity> walletDetailsEntities) {
                data.addAll(walletDetailsEntities);
                adapter = new WalletDetailsAdatper(data, MyWalletDetailsActivity.this);
                mListView.setAdapter(adapter);
            }
        });

    }

}
